<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ArctypeModel
 *
 * @author zw
 * time 2014-8-16
 */

namespace Admin\Model;

use Think\Model;

class ArctypeModel extends Model {
    //表单提交字段自动验证
    protected $_validate = array(
        array('title', 'require', '名称不能为空', self::MUST_VALIDATE , 'regex', self::MODEL_BOTH),
        array('meta_title', '1,50', '网页标题不能超过50个字符', self::VALUE_VALIDATE , 'length', self::MODEL_BOTH),
        array('keywords', '1,255', '网页关键字不能超过255个字符', self::VALUE_VALIDATE , 'length', self::MODEL_BOTH),
        array('meta_title', '1,255', '网页描述不能超过255个字符', self::VALUE_VALIDATE , 'length', self::MODEL_BOTH),
    );

    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH),
        array('status', '1', self::MODEL_BOTH),
    );

    //获取分类信息
    public function getMenuTree($arrCat, $pid = 0, $level = 0) {

        static $arrTree = array(); //使用static代替global
        if (empty($arrCat))
            return FALSE;

        $level++;

        foreach ($arrCat as $key => $value) {
            if ($value['pid'] == $pid) {
                $value['level'] = $level;
                $arrTree[] = $value;
                unset($arrCat[$key]); //注销当前节点数据，减少已无用的遍历
                $this->getMenuTree($arrCat, $value['id'], $level);
            }
        }
        return $arrTree;
    }


}

?>
